#include "MyButton.h"

MyButton::MyButton(QString iconName, QWidget* parent)
{
	this->setParent(parent);
	this->resize(parent->width(), parent->width());
	this->setCursor(Qt::PointingHandCursor);
	this->setMouseTracking(true);
	this->defaultStyle();
	this->m_iconName = iconName;
	this->changeIcon(this->m_iconName);
}

MyButton::MyButton(QString iconName, int width, int height, QWidget* parent): MyButton(iconName, parent)
{
	this->resize(width, height);
	this->move((parent->width() - width) / 2, (parent->height() - height) / 2);
}

MyButton::~MyButton()
{
}

void MyButton::enterEvent(QEnterEvent* ev)
{
	this->checkStyle();
}

void MyButton::leaveEvent(QEvent* ev)
{
	this->defaultStyle();
}

void MyButton::changeIcon(QString icon)
{
	this->setIcon(QIcon("./icon/" + icon + ".png"));
	this->setIconSize(QSize(0.6 * this->width(), 0.6 * this->height()));
}

void MyButton::defaultStyle()
{
	this->changeIcon(this->m_iconName);
	this->setStyleSheet("background-color: transparent;");
}

void MyButton::checkStyle()
{
	this->changeIcon(this->m_iconName + "_checked");
	this->setStyleSheet("background-color: #F55757; border: none; border-radius:5px;");
}
